package staticClasses;

import java.util.ArrayList;

import players.*;



public class Initialization {
	
	public static void InitBall(){
		Global.ball = new Ball();
		int[] pos = {Global.center.x,Global.center.y};
		Global.ball.setPosition(pos[0], pos[1]);
		Global.ball.targeted_case[0] = pos[0];
		Global.ball.targeted_case[1] = pos[1];
		Global.ball.velocity = 0;
		Global.setBallOwner(null);
	}
	
	public static void InitLocalTeam(){
		Global.localTeam = new ArrayList<Player>();
		GoalKeeper goal = new GoalKeeper(Global.localTeam_6meter);

		Fullback fb_north = new Fullback(Global.Map[Global.MapSize[0]/5][3*Global.MapSize[1]/4]);
		Fullback fb_south = new Fullback(Global.Map[Global.MapSize[0]/5][Global.MapSize[1]/4]);

		Forward fw_north = new Forward(Global.Map[4*Global.MapSize[0]/9][3*Global.MapSize[1]/4]);
		Forward fw_south = new Forward(Global.Map[4*Global.MapSize[0]/9][Global.MapSize[1]/4]);
		
		MidFielder mf = new MidFielder(Global.Map[1*Global.MapSize[0]/3][Global.MapSize[1]/2]);
		
		Global.localTeam.add(goal);
		Global.localTeam.add(fb_north);
		Global.localTeam.add(fb_south);
		Global.localTeam.add(fw_north);
		Global.localTeam.add(fw_south);
		Global.localTeam.add(mf);
	}
	
	public static void InitVisitorTeam(){
		Global.visitorTeam = new ArrayList<Player>();
		GoalKeeper goal = new GoalKeeper(Global.visitorTeam_6meter);

		Fullback fb_north = new Fullback(Global.Map[4*Global.MapSize[0]/5][3*Global.MapSize[1]/4]);
		Fullback fb_south = new Fullback(Global.Map[4*Global.MapSize[0]/5][Global.MapSize[1]/4]);

		Forward fw_north = new Forward(Global.Map[5*Global.MapSize[0]/9][3*Global.MapSize[1]/4]);
		Forward fw_south = new Forward(Global.Map[5*Global.MapSize[0]/9][Global.MapSize[1]/4]);
		
		MidFielder mf = new MidFielder(Global.Map[2*Global.MapSize[0]/3][Global.MapSize[1]/2]);
		
		Global.visitorTeam.add(goal);
		Global.visitorTeam.add(fb_north);
		Global.visitorTeam.add(fb_south);
		Global.visitorTeam.add(fw_north);
		Global.visitorTeam.add(fw_south);
		Global.visitorTeam.add(mf);
		
		for(Player p:Global.visitorTeam){
			p.isInLocalTeam=false;
		}
	}
	
	public static void InitLevelTeam(ArrayList<Player> team, PlayerLevel level){
		for(Player p:team){
			p.setLevel(level);
		}
	}
	
	public static void InitLevelTeam(PlayerLevel level, ArrayList<Player> team){
		InitLevelTeam(team, level);
	}
	
	public static void InitMap(){
		Global.localTeam_goalLine = new ArrayList<int[]>();
		Global.visitorTeam_goalLine = new ArrayList<int[]>();
		Global.midLine = new ArrayList<int[]>();
		Global.leftLine = new ArrayList<int[]>();
		Global.rightLine = new ArrayList<int[]>();
		Global.topLine = new ArrayList<int[]>();
		Global.bottomLine = new ArrayList<int[]>();
		Global.Map = new Square[Global.MapSize[0]][Global.MapSize[1]];
		
		for(int x=0;x<Global.MapSize[0];x++){
			for(int y=0;y<Global.MapSize[1];y++){
				Square s = new Square(x, y);
				int[] tab = new int[2];
				tab[0] = x; tab[1] = y;
				Global.Map[x][y] = s;
				if(x==0){
					//we add the left line
					Global.leftLine.add(tab);
				}
				if(x==(Global.MapSize[0]-1)){
					//we add the right line
					Global.rightLine.add(tab);
				}
				if(y==0){
					//we add the bottom line
					Global.bottomLine.add(tab);
				}
				if(y==(Global.MapSize[1]-1)){
					//we add the top line
					Global.topLine.add(tab);
				}
				if(x==((Global.MapSize[0]-1)/2) && y==((Global.MapSize[1]-1)/2)){
					//We add the center of the field
					Global.center = s;
				}
				if(x==0 && y<=((Global.MapSize[1]-1)/2+36) && y>=((Global.MapSize[1]-1)/2-36)){
					//We add the goal Line of left team (local team)
					Global.localTeam_goalLine.add(tab);
				}
				if(x==(Global.MapSize[0]-1) && y<=((Global.MapSize[1]-1)/2+36) && y>=((Global.MapSize[1]-1)/2-36)){
					// We add the goal line of the right team (visitor team)
					Global.visitorTeam_goalLine.add(tab);
				}
				if( y==((Global.MapSize[1]-1)/2) && x==55 ){
					//we add the 6-meter point of local team
					Global.localTeam_6meter = s;
				}
				if( y==((Global.MapSize[1]-1)/2) && x==((Global.MapSize[0]-1)-55) ){
					//we add the 6-meter point of visitor team
					Global.visitorTeam_6meter = s;
				}
			}
		}
	}
	
	
}
